package com.zues.thread.method.interrupt;

import com.zues.thread.util.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName Demo2
 * @Description 测试线程打断方法
 * interrupt()打断这个线程，异常处理机制
 * 打断正常运行的线程：不会清空打断状态（true）
 * @Author zeus
 * @Date 2/28/2025 5:10 下午
 * @Version 1.0
 **/
@Slf4j(topic = "c.Demo2")
public class Demo2 {

    public static void main(String[] args) throws InterruptedException {
        Thread t2 = new Thread(() -> {
            while (true) {
                boolean interrupted = Thread.currentThread().isInterrupted();
                if (interrupted) {
                    log.info(" 打断状态: {}", interrupted);//打断状态: {}true
                    break;
                }
            }
        }, "t2");
        t2.start();
        Thread.sleep(5000);
        t2.interrupt();
    }

}
